package com.xueyu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xueyu.dao.StayinfoDao;
import com.xueyu.dao.bedManageDao;
import com.xueyu.dao.personinfoDao;
import com.xueyu.domain.Relative.RelativeBean;
import com.xueyu.domain.bed.bedBean;
import com.xueyu.domain.personinfo.personinfoBean;
import com.xueyu.util.ResultBean;
import com.xueyu.domain.Stayinfo.StayinfoBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

//住宿安排
@RestController
@RequestMapping("/Stayinfo")
public class StayinfoController {
    @Autowired
    StayinfoDao StayinfoDao;
    @Autowired
    personinfoDao personinfoDao;
    @Autowired
    bedManageDao bedDao;

    @RequestMapping("/add")
    public ResultBean add(@RequestBody StayinfoBean StayinfoBean)throws Exception{
        ResultBean ResultBean= new ResultBean();
        if (StayinfoBean.getStayId()==0){
            StayinfoDao.insert(StayinfoBean);
        }else{
            StayinfoDao.updateById(StayinfoBean);
        }
        return ResultBean;
    }
    //    删除
    @RequestMapping("/del/{stayId}")
    public ResultBean del(@PathVariable("stayId") int stayId){
        StayinfoDao.deleteById(stayId);
        return  new ResultBean();
    }


    @RequestMapping("/getid/{stayId}")
    public Map<String, Object> getId(@PathVariable("stayId") int stayId){
        ResultBean resultBean = new ResultBean();
        if (stayId>0) {
            QueryWrapper<StayinfoBean> queryWrapper = Wrappers.query();
            queryWrapper.eq("stayId", stayId);
            List<StayinfoBean> StayinfoList = StayinfoDao.selectList(queryWrapper);
            resultBean.put("data", StayinfoList);
        }
        return resultBean;
    }
    //    分页
    @RequestMapping("/list")
    public ResultBean list(@RequestBody Map map){
        int current = (Integer)map.get("Current");
        int size = (Integer)map.get("size");
        String search = (String) map.get("search");
        Page<StayinfoBean> page = new Page<StayinfoBean>(current,size);
        List<StayinfoBean> list = StayinfoDao.selectLeftJoin(search,page);
        System.out.println("list======"+list);
        ResultBean resultBean = new ResultBean();
        resultBean.put("list",list);
        resultBean.put("total",page.getTotal());
        return resultBean;
    }

}
